﻿using GameSave.Entity;
using System;
using System.Collections.Generic;
using System.Data;
using System.IO;

namespace GameSave
{
    /// <summary>
    /// 游戏存档管理器
    /// </summary>
    public class GameSaveManager
    {
        private SqliteManager summarySaveSqliteMng;
        private List<GameSaveUnit> gameSaveList;
        /// <summary>
        /// 初始化，获取默认存档管理数据库，如果没有则创建一个
        /// </summary>
        public void Init(string summarySaveSqlitePath)
        {
            IDbConnection conn = null;
            if(summarySaveSqliteMng == null)
            {
                summarySaveSqliteMng = new SqliteManager();
                conn = TryGetConn(summarySaveSqlitePath);
            }
        }

        private IDbConnection TryGetConn(string path)
        {
            IDbConnection conn = null;
            bool isNeedCreate = false;
            try
            {
                conn = summarySaveSqliteMng.CreateConnection(path);
            }
            catch (BadImageFormatException e)
            {
                // 没有该文件，可以自动创建
                isNeedCreate = true;
            }

            if(isNeedCreate)
            {
                FileStream fs = new FileStream(path, FileMode.OpenOrCreate, FileAccess.ReadWrite);
            }

            return summarySaveSqliteMng.CreateConnection(path);
        }

        public void LoadSave()
        {

        }
    }
}
